package com.glory.wxelectricitypda.activity;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.glory.wxelectricitypda.R;
import com.glory.wxelectricitypda.base.Constant;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_TextCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_SharePreferencesUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_Utils;

import butterknife.BindView;
import butterknife.OnClick;

public class SettingActivity extends FreeUI_BaseActivity {

    @BindView(R.id.tvIP)
    TextView tvIP;
    @BindView(R.id.rlIP)
    RelativeLayout rlIP;
    @BindView(R.id.tvVersion)
    TextView tvVersion;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvFileIP)
    TextView tvFileIP;
    @BindView(R.id.tvPrintIP)
    TextView tvPrintIP;
    @BindView(R.id.tvPrintIP2)
    TextView tvPrintIP2;

    private FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        freeUI_titleView.setTitle("设置");
    }

    @Override
    protected void initData() {
        tvVersion.setText(String.valueOf(Constant.VERSION_CODE));
        tvIP.setText(Constant.REQUEST_URL);
        tvFileIP.setText(Constant.FILE_URL);
        tvPrintIP.setText(Constant.PRINT_IP);
        tvPrintIP2.setText(Constant.PRINT_IP2);
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return new FreeUI_AddViewEntity(getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY), llMain);
    }

    @OnClick({R.id.rlIP, R.id.rlFileIP, R.id.rlPrintIP, R.id.rlPrintIP2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rlIP:
                freeUI_generalFragmentDialog = FreeApi_DialogUtils.getScanDialog(this, "请输入IP地址", Constant.REQUEST_URL, new FreeUI_TextCallback() {
                    @Override
                    public void onSuccess(String s) {
                        freeUI_generalFragmentDialog.dismiss();
                        Constant.REQUEST_URL = s;
                        tvIP.setText(Constant.REQUEST_URL);
                        FreeApi_SharePreferencesUtils.setSharePre("URL_FILE", "URL_IP", s, getApplicationContext());
                        showToast("保存成功", true);
                    }
                });
                freeUI_generalFragmentDialog.show(getSupportFragmentManager(), "URL_IP_DIALOG");
                break;
            case R.id.rlFileIP:
                freeUI_generalFragmentDialog = FreeApi_DialogUtils.getScanDialog(this, "请输入IP地址", Constant.FILE_URL, new FreeUI_TextCallback() {
                    @Override
                    public void onSuccess(String s) {
                        freeUI_generalFragmentDialog.dismiss();
                        Constant.FILE_URL = s;
                        tvFileIP.setText(Constant.FILE_URL);
                        FreeApi_SharePreferencesUtils.setSharePre("URL_FILE", "FILE_IP", s, getApplicationContext());
                        showToast("保存成功", true);
                    }
                });
                freeUI_generalFragmentDialog.show(getSupportFragmentManager(), "FILE_IP_DIALOG");
                break;
            case R.id.rlPrintIP:
                freeUI_generalFragmentDialog = FreeApi_DialogUtils.getScanDialog(this, "请输入IP地址", Constant.PRINT_IP, new FreeUI_TextCallback() {
                    @Override
                    public void onSuccess(String s) {
                        freeUI_generalFragmentDialog.dismiss();
                        Constant.PRINT_IP = s;
                        tvPrintIP.setText(Constant.PRINT_IP);
                        FreeApi_SharePreferencesUtils.setSharePre("URL_FILE", "PRINT_IP", s, getApplicationContext());
                        showToast("保存成功", true);
                    }
                });
                freeUI_generalFragmentDialog.show(getSupportFragmentManager(), "PRINT_IP_DIALOG");
                break;
            case R.id.rlPrintIP2:
                freeUI_generalFragmentDialog = FreeApi_DialogUtils.getScanDialog(this, "请输入IP地址", Constant.PRINT_IP2, new FreeUI_TextCallback() {
                    @Override
                    public void onSuccess(String s) {
                        freeUI_generalFragmentDialog.dismiss();
                        Constant.PRINT_IP2 = s;
                        tvPrintIP2.setText(Constant.PRINT_IP2);
                        FreeApi_SharePreferencesUtils.setSharePre("URL_FILE", "PRINT_IP2", s, getApplicationContext());
                        showToast("保存成功", true);
                    }
                });
                freeUI_generalFragmentDialog.show(getSupportFragmentManager(), "PRINT_IP2_DIALOG");
                break;
        }
    }
}

